import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

//void main() => runApp(MyThemePage());

class MyThemePage extends StatelessWidget {
  final ThemeData kIOSTheme = ThemeData(
      brightness: Brightness.light,
      accentColor: Colors.white,
      primaryColor: Colors.blue,
      iconTheme: IconThemeData(color: Colors.grey),
      textTheme: TextTheme(body1: TextStyle(color: Colors.black)));

  final ThemeData kAndroidTheme = ThemeData(
      brightness: Brightness.dark,
      accentColor: Colors.black,
      primaryColor: Colors.cyan);

  Widget build(BuildContext context) {
    var theme = MyTheme(
      title: '嘻嘻嘻嘻嘻',
      themes: [kIOSTheme, kAndroidTheme],
    );
    return MaterialApp(
      title: 'My Theme',
      theme: kAndroidTheme,
      home: theme,
    );
  }
}

class MyTheme extends StatefulWidget {
  MyTheme({Key key, this.title, this.themes}) : super(key: key);

  final String title;
  final List<ThemeData> themes;

  _MyThemeState createState() => _MyThemeState();
}

class _MyThemeState extends State<MyTheme> {
  bool isLight = false;

  @override
  Widget build(BuildContext context) {
    return Theme(
        child: Scaffold(
          appBar: AppBar(title: Text('主题变更')),
          body: Text('哈哈哈哈哈'),
          floatingActionButton: FloatingActionButton(
              child: Text(isLight ? 'Night' : 'Light'),
              onPressed: () {
                setState(() {
                  isLight = !isLight;
                });
              }),
        ),
        data: isLight ? widget.themes[0] : widget.themes[1]);
  }
}
